package model.primitive;

import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import model.ray.Ray;




public class IntersectionData implements Comparable<IntersectionData>{
	public Point3d hitPoint;
	public Vector3d normal;
	public Primitive primitive;
	public Double distance;
	public Ray intersectRay; // rayo que intersecto desde la camara con la primitiva


	public IntersectionData (Ray intersectRay, Primitive primitive, Vector3d normal, Point3d hitPoint, Double distance) {
		this.primitive = primitive;
		this.normal = normal;
		this.hitPoint = hitPoint;
		this.distance = distance;
		this.intersectRay = intersectRay;
	}
	

	public IntersectionData(Ray intersectRay, Primitive primitive, Point3d hitPoint,
			Double distance) {
		this(intersectRay, primitive, null, hitPoint, distance);
	}

	public IntersectionData(Ray intersectRay, Primitive primitive, 
			Double distance) {
		this(intersectRay, primitive, null, null, distance);
	}

	public Point3d getHitPoint() {
		return hitPoint;
	}

	public void setHitPoint(Point3d hitPoint) {
		this.hitPoint = hitPoint;
	}

	public Vector3d getNormal() {
		if (this.normal == null) {
			this.normal = this.primitive.getNormal(this.hitPoint);
		}
		
		return new Vector3d(this.normal);
		
	}

	public Primitive getPrimitive() {
		return primitive;
	}

	public void setPrimitive(Primitive primitive) {
		this.primitive = primitive;
	}


	@Override
	public int compareTo(IntersectionData o) {
		int ret;
		if (this.distance > o.distance) {
			ret = 1;
		} else if (this.distance < o.distance) {
			ret = -1;
		} else {
			ret = 0;
		}
		return ret;
	}
	
	@Override
	public String toString(){
		return "Interseccion en " + this.hitPoint!= null?this.hitPoint.toString():"";
	}
}
